<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <ul id="ul"></ul>

  <script>
    function getData() {
      return new Promise((resolve, reject) => {
        let xhr = new XMLHttpRequest()//帮我们创建一个http请求体实例对象
        xhr.open('GET', 'https://mock.mengxuegu.com/mock/65a91543c4cd67421b34c898/movie/movieList', true)
        xhr.send()// 发送请求
        xhr.onreadystatechange = function () {
          if (xhr.readyState === 4 && xhr.status === 200) {
            console.log(JSON.parse(xhr.responseText));// 解析成功后获得的数据
            resolve(JSON.parse(xhr.responseText).movieList)// 拿到数据并且返回到then中赋值给res
          }
        }// 监听状态变更
      })
    }

    function showList(data) {
      data.forEach(item => {
        let li = document.createElement('li')
        li.innerText = item.nm
        document.getElementById('ul').appendChild(li)
      });
      // console.log(`拿到了数据${data}`);
    }
    getData().then((res) => { showList(res) })
  </script>
</body>
</html>